package logic

import (
	"bw-renting/user-rpc/userclient"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAuthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAuthLogic {
	return &UserAuthLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 实名认证
func (l *UserAuthLogic) UserAuth(req *types.AuthUserReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.UserServer.Real(context.Background(), &userclient.RealNameReq{
		Name: req.RealName,
		Code: req.IdCode,
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    500,
			Message: "实名验证失败",
			Data:    nil,
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "实名验证成功",
		Data:    nil,
	}, nil
}
